cc.Class({
    extends: cc.Component,

    properties: {

    },


    onLoad() {
        this.lobbyMain = cc.find("Canvas").getComponent("lobbyMain");
        this.lobbyNet = this.lobbyMain.lobbyNet;
        this.playerInfo = this.lobbyMain.playerInfo;


        this.nameLabel = this.node.getChildByName("name").getComponent(cc.Label);
        this.multipleLabel = this.node.getChildByName("multiple").getComponent(cc.Label);
        this.headSprite = this.node.getChildByName("headBg").getChildByName("head").getComponent(cc.Sprite);
        this.gameSprite = this.node.getChildByName("gameIcon").getComponent(cc.Sprite);

        this.bundle = cc.assetManager.getBundle("panel")
        this.state = 0;  //0可移动 1不能动
    },

    start() {
        this.node.y = 450
    },

    //当推送大奖信息的时候
    onTuiSongWin(data) {
        if (this.state == 1) {
            return;
        }
        this.nameLabel.string = data.name;
        this.multipleLabel.string = data.multiple + "x";

        this.loadHeadImg(data);
        this.loadGameImg(data);
    },

    moveWinChuang() {
        cc.tween(this.node)
            .to(0.5, { y: this.node.y - 210 }) // 1秒内下移210
            .delay(3)                         // 停留2秒
            .to(0.5, { y: this.node.y })       // 再上移210（回到原位置）
            .call(() => {
                this.state = 0;
            })
            .start();
    },


    //加载头像
    loadHeadImg(data) {
        this.state = 1
        const imagePath = "image/head/tx_head" + data.headId;
        const bundle = cc.assetManager.getBundle("hall");
        if (!bundle) {
            cc.error("未找到 bundle：hall");
            return;
        }
        bundle.load(imagePath, cc.SpriteFrame, (err, spriteFrame) => {
            if (err) {
                cc.error("加载头像失败：" + (err.message || err));
                return;
            }
            if (!this.headSprite) return;
            this.headSprite.spriteFrame = spriteFrame;
        });
    },

    //加载游戏图标
    loadGameImg(data) {
        const imagePath = "image/game/small/" + data.gameName;
        const bundle = cc.assetManager.getBundle("hall");
        if (!bundle) {
            cc.error("未找到 bundle：hall");
            return;
        }
        bundle.load(imagePath, cc.SpriteFrame, (err, spriteFrame) => {
            if (err) {
                cc.error("加载图标失败：" + (err.message || err));
                return;
            }
            if (!this.gameSprite) return;
            this.gameSprite.spriteFrame = spriteFrame;
            this.moveWinChuang();
        });
    },



    // update (dt) {},
});
